<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta name="_token" content="{{ csrf_token() }}" />
<!--[if lt IE 9]>
<script type="text/javascript" src="../lib/html5.js"></script>
<script type="text/javascript" src="../lib/respond.min.js"></script>
<script type="text/javascript" src="../lib/PIE_IE678.js"></script>
<![endif]-->
<link href="/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="/lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
<link href="/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>新增活动内容</title>
</head>
<body>
<div class="pd-20">
	<form action="{{ url('event/create',['id'=>$id]) }}" method="post" class="form form-horizontal" id="form-article-add">
		<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>活动归属（4S店）：</label>
			<div class="formControls col-4"> 
			<span class="select-box">
				云南驰泰汽车销售服务有限公司	
			</span>  
			</div>
			<label class="form-label col-2"><span class="c-red">*</span>活动类型：</label>
			<div class="formControls col-2"> 
			<span class="select-box ">
			<select name="act_type" class="select" id="act_type">
				<option value="1" selected='selected'>店内活动</option>
				<option value="2" >金融方案</option>
				<option value="3" >二手车活动</option>
				<option value="5" >维修活动</option>				
			</select>
			</span> 
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>活动标题：</label>
			<div class="formControls col-8">
				<input type="text" class="input-text" value="" placeholder="请输入活动标题" id="title" name="title">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>活动简介：</label>
			<div class="formControls col-8">
				<input type="text" class="input-text" value="" placeholder="请输入活动简介" id="summary" name="summary">
			</div>
		</div>	
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>填报日期：</label>
			<div class="formControls col-8">
				<input type="text" class="input-text" value="2016-07-26" placeholder="" id="actdate" name="actdate">
			</div>
		</div>			
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>图片：</label>
			<div class="formControls col-8">
			<span class="btn-upload">
				<span class="btn btn-primary radius">请选择文件</span>
				<input type="file" name="pic" id="pic" value="" class="input-file">
			</span>
			<div class="text-l" id="loading" style="display:none;" >
				<img style="margin-top:50px; width:100px;height:100px;" id="" src="/crop/images/loadingBar.gif">
			<div>文件检测上传中...</div>
			</div>
				<button id="btn-selectpic" type="button" class="btn btn-default radius ml-10" style='margin-left:30px;'>从图库选择</button>
				<input type="hidden" class="input-text" name="titlepic" id="titlepic">
			<div class="pic-box" id="fileList" class="uploader-list"><img style="width:200px;height:133px;display:none;" id="showpic" ></div>
			</div>
		</div>
		<!--<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>活动头图片：</label>
			<div class="formControls col-6">
				<div class="uploader-thum-container">
					<!--<div id="fileList" class="uploader-list"></div>-->
					<!--缩略图 -->
					<!--<div id="" class="item">
				<div class="pic-box" id="fileList" class="uploader-list"><img></div>
				<div class="info"></div>
				<p class="state"></p>
			</div>
					
					<div id="filePicker">选择图片</div>
					<button id="btn-selectpic" type="button" class="btn btn-default radius ml-10">从图库选择</button>
					<input type="hidden" class="input-text" name="titlepic" id="titlepic">
				</div>
			</div>
		</div>-->
		
		<div class="row cl" id="contentshow">
			<label class="form-label col-3">活动文章内容：</label>
			<div class="formControls col-8"> 
				<script id="editor" type="text/plain" style="width:100%;height:400px;"></script> 
			</div>
		</div>
		<div class="row cl">
			<div class="col-7 col-offset-4">
				<span class="btn btn-primary radius" id="submit" onclick="view('预览视图','Portal_Actview.php','320','600')" ><i class="Hui-iconfont">&#xe695;</i> 预 览 </span>
				<!--<button class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 提 交 </button>-->
				<button onClick="close_layer()" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
				<span class="btn btn-primary radius"  onclick="baocun()" ><i class="Hui-iconfont">&#xe632;</i> 保 存 </span>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript" src="/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="/lib/layer/1.9.3/layer.js"></script> 
<script type="text/javascript" src="/lib/laypage/1.2/laypage.js"></script> 
<script type="text/javascript" src="/lib/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="/lib/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="/lib/Validform/5.3.2/Validform.min.js"></script> 
<script type="text/javascript" src="/lib/webuploader/0.1.5/webuploader.min.js"></script> 
<script type="text/javascript" src="/lib/ueditor/1.4.3/ueditor.config.js"></script> 
<script type="text/javascript" src="/lib/ueditor/1.4.3/ueditor.all.min.js"> </script> 
<script type="text/javascript" src="/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script> 
<script type="text/javascript" src="/js/H-ui.js"></script> 
<script type="text/javascript" src="/js/H-ui.admin.js"></script> 
<!-- 裁剪上传处理-->
<script type="text/javascript" src="/crop/js/jquery-1.7.1.min.js"></script> 
<script type="text/javascript" src="/crop/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="/crop/js/artDialog4.1.6/jquery.artDialog.js?skin=default"></script>
<script type="text/javascript" src="/crop/js/artDialog4.1.6/plugins/iframeTools.js"></script>
<script type="text/javascript">
$(function(){
		
	
	
	//从已有图库选择图片
	$("#btn-selectpic").click(function(){
		layer.open({
			type: 2,
			area: ['780px', '530px'],
			fix: false, //不固定
			maxmin: true,
			content: 'Include_PicturePeek.php'
		});
	});
	//上传图片
	/*$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$list = $("#fileList"),
	$btn = $("#btn-star"),
	state = "pending",
	uploader;

	var uploader = WebUploader.create({
		auto: true,
		swf: '../lib/webuploader/0.1.5/Uploader.swf',
	
		// 文件接收服务端。
		server: 'Include_Fileupload.php',
	
		// 选择文件的按钮。可选。
		// 内部根据当前运行是创建，可能是input元素，也可能是flash.
		pick: '#filePicker',
	
		// 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
		resize: false,
		// 只允许选择图片文件。
		accept: {
			title: 'Images',
			extensions: 'gif,jpg,jpeg,bmp,png',
			mimeTypes: 'image/*'
		}
	});
	//缩略图
	uploader.on('fileQueued',function( file ){
	
		$(".item").attr("id", "'"+file.id +"'");
		$(".info").val("'"+file.name+"'");
		$img=$(".item").find('img');
		uploader.makeThumb( file, function( error, src ) {
			if ( error ) {
				$img.replaceWith('<span>不能预览</span>');
				return;
			}
	
			$img.attr( 'src', src );
		}, 150, 100 );
	});
	*/
	/*uploader.on( 'fileQueued', function( file ) {
		var $li = $(
			'<div id="' + file.id + '" class="item">' +
				'<div class="pic-box"><img></div>'+
				'<div class="info">' + file.name + '</div>' +
				'<p class="state">等待上传...</p>'+
			'</div>'
		),
		$img = $li.find('img');
		$list.append( $li );
	
		// 创建缩略图
		// 如果为非图片文件，可以不用调用此方法。
		// thumbnailWidth x thumbnailHeight 为 100 x 100
		uploader.makeThumb( file, function( error, src ) {
			if ( error ) {
				$img.replaceWith('<span>不能预览</span>');
				return;
			}
	
			$img.attr( 'src', src );
		}, 150, 100 );
	});*/
	// 文件上传过程中创建进度条实时显示。
	/*uploader.on( 'uploadProgress', function( file, percentage ) {
		var $li = $( '#'+file.id ),
			$percent = $li.find('.progress-box .sr-only');
	
		// 避免重复创建
		if ( !$percent.length ) {
			$percent = $('<div class="progress-box"><span class="progress-bar radius"><span class="sr-only" style="width:0%"></span></span></div>').appendTo( $li ).find('.sr-only');
		}
		$li.find(".state").text("上传中");
		$percent.css( 'width', percentage * 100 + '%' );
	});
	
	// 文件上传成功，给item添加成功class, 用样式标记上传成功。
	uploader.on( 'uploadSuccess', function( file ) {
		$( '#'+file.id ).addClass('upload-state-success').find(".state").text("已上传");
	});
	
	// 文件上传失败，显示上传出错。
	uploader.on( 'uploadError', function( file ) {
		$( '#'+file.id ).addClass('upload-state-error').find(".state").text("上传出错");
	});
	//解析返回json
	uploader.on( 'uploadAccept', function( file, response ) {
		//删除前一个选择的图片
		if($("#titlepic").val().length>0){
		ajRusult=$.ajax({url:"Picture_AJAX.php?act=picdelete&pic="+$("#titlepic").val(),async:false});}
			
		$("#titlepic").val(response._raw);*/
    /*if ( hasError ) {
        // 通过return false来告诉组件，此文件上传有错。
        return false;
    }*/
/*	});
	// 完成上传完了，成功或者失败，先删除进度条。
	uploader.on( 'uploadComplete', function( file ) {
		$( '#'+file.id ).find('.progress-box').fadeOut();
	});
	uploader.on('all', function (type) {
        if (type === 'startUpload') {
            state = 'uploading';
        } else if (type === 'stopUpload') {
            state = 'paused';
        } else if (type === 'uploadFinished') {
            state = 'done';
        }

        if (state === 'uploading') {
            $btn.text('暂停上传');
        } else {
            $btn.text('开始上传');
        }
    });

    $btn.on('click', function () {
        if (state === 'uploading') {
            uploader.stop();
        } else {
            uploader.upload();
        }
    });

	*/
	
	var ue = UE.getEditor('editor');
		//完成编辑提示


////***********裁剪文件按钮
	$('#pic').live('change',function(){ 
		ajaxFileUploadview('pic','titlepic',"crop/upload.php");
	});
});

//关闭弹窗提醒
 function close_layer(){
	 layer.confirm('关闭本窗口？您所编辑的内容将不复存在！',function(){
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		});	
 }
//****************裁剪上传处理
function insql(file){
	//alert(file);
		$("#showpic").attr('src',file);
		$("#showpic").show();
		$("#titlepic").attr('value',file);		
}

//预览活动
function view(title,url,w,h){
	//layer_show(title,url,w,h);
	//获取输入的值 并储存到本地 localstroage
	 localStorage['act_type']=$('#act_type').val();
	 var act_type=$('#act_type').val();
	 var title=$('#title').val();
	 var summary=$('#summary').val();
	 var actdate=$('#actdate').val();
	 var titlepic=$('#titlepic').val();
	 var editorvalue=$("textarea[name='editorValue']").val();
	 if(title==""){ 
	 layer.msg('请输入活动标题!',{icon: 2,time:1000});
	 }else if(summary==""){
		 layer.msg('请输入活动简介!',{icon: 2,time:1000});
	 }else if( actdate==""){
		 layer.msg('请输入填表日期!',{icon: 2,time:1000});
	 }else if(titlepic==''){
		 layer.msg('请选择图片!',{icon: 2,time:1000});
	 }else if( editorvalue==''){
		 layer.msg('请输入详情内容!',{icon: 2,time:1000});
	 }else{
	 
	 localStorage['title']=$('#title').val();
	 localStorage['summary']=$('#summary').val();
	 localStorage['actdate']=$('#actdate').val();
	 localStorage['titlepic']=$('#titlepic').val();
	 localStorage['editorValue']=$("textarea[name='editorValue']").val();

	layer.open({
		type: 2,
		area: ['320px', h +'px'],
		fix: true, //固定
		maxmin: true,
		shade:0.4,
		title: title,
		content: url,
	}); 
}
}

//提交表单数据
function baocun(){
	 var act_type=$('#act_type').val();
	 var title=$('#title').val();
	 var summary=$('#summary').val();
	 var actdate=$('#actdate').val();
	 var titlepic=$('#titlepic').val();
	 var editorValue=$("textarea[name='editorValue']").val();
	 if(title==""){ 
		layer.msg('请输入活动标题!',{icon: 2,time:1000});
	 }else if(summary==""){
		 layer.msg('请输入活动简介!',{icon: 2,time:1000});
	 }else if( actdate==""){
		 layer.msg('请输入填表日期!',{icon: 2,time:1000});
	 }else if(titlepic==''){
		 layer.msg('请选择图片!',{icon: 2,time:1000});
	 }else if( editorValue==''){
		 layer.msg('请输入详情内容!',{icon: 2,time:1000});
	 }else{
	$.ajax({
		url			:	"{{ url('event/create',['id'=>$id]) }}",  
		dataType	:	"json",  
		data		:	{act:'actadd',act_type:act_type,title:title,summary:summary,actdate:actdate,titlepic:titlepic,editorValue:editorValue },
		async		:	false,  			
		type		:	"post",
		success		:	function(data){
			layer.confirm('添加成功，是否关闭本窗口？',function(){
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index);
				
			});	
		}
	 });
	 }
	
}

//文件上传带预览
function ajaxFileUploadview(imgid,hiddenid,url){
		var info="列表图";
		var acc="loc";
		if(acc=="fin"){
			var info="金融方案";
		}else if(acc=="useact"){
			var info="二手车";
		}
		var id=Math.ceil(Math.random()*10);
		var name='logan'+id;
		var pictype="";
		$('#loading').fadeIn();//显示加载
		$.ajaxFileUpload
		({
			url:url,
			secureuri:false,
			fileElementId:imgid,
			dataType: 'json',
			data:{name:name, id:id},
			success: function (data, status)
			{
				$('#loading').fadeOut();//隐藏加载
				if(typeof(data.error) != 'undefined')
				{
					if(data.error != '')
					{
					
					layer.msg(data.error,{icon: 2,time:2000});
						/* var dialog = art.dialog({title:false,fixed: true,padding:0});
						dialog.time(2).content("<div class='tips'>"+data.error+"</div>"); */
					}else{

						var resp = data.msg;						
						if(resp != '0000'){
							var dialog = art.dialog({title:false,fixed: true,padding:0});
							dialog.time(2).content("<div class='tips'>"+data.error+"</div>");
							return false;
						}else{
							$('#'+hiddenid).val(data.imgurl);						

							art.dialog.open("crop/crop_image.php?img="+data.imgurl+"&pictype="+pictype+"&info="+info,{
							//裁剪页面大小
								title: '图片裁剪',
								width:'70%',
								height:'400px'
							});						
							
							// dialog.time(3).content("<div class='msg-all-succeed'>上传成功！</div>");
						}
					}
				}
			},
			error: function (data, status, e)
			{

				dialog.time(3).content("<div class='tips'>"+e+"</div>");
			}
		})

		return false;
	}
	
</script>
</body>
</html>